const Mock = require('mockjs')

// mock超时超时
Mock.setup({
    timeout: '200-600'
});

let configArray = []

// 使用webpack检测文件夹下的所有mock文件
const files = require.context('.', true, /\.js$/);

console.log(files)
files.keys().forEach((key) => {
  if (key === './index.js') return;
  configArray = configArray.concat(files(key).default);
});

// 注册所有的mock服务
configArray.forEach((item) => {
  for (let [path, target] of Object.entries(item)) {
    let protocol = path.split('|');
    Mock.mock(new RegExp('^' + protocol[1]), protocol[0], target);
  }
});
